home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / tests / set.test < prev    next >
Encoding:
Text File  |  1995-02-18  |  20.8 KB  |  669 lines

  1. # Commands covered:  set, unset, array
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) set.test 1.15 95/02/18 14:55:48
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. proc ignore args {}
  18.  
  19. # Simple variable operations.
  20.  
  21. catch {unset a}
  22. test set-1.1 {basic variable setting and unsetting} {
  23.     set a 22
  24. } 22
  25. test set-1.2 {basic variable setting and unsetting} {
  26.     set a 123
  27.     set a
  28. } 123
  29. test set-1.3 {basic variable setting and unsetting} {
  30.     set a xxx
  31.     format %s $a
  32. } xxx
  33. test set-1.4 {basic variable setting and unsetting} {
  34.     set a 44
  35.     unset a
  36.     list [catch {set a} msg] $msg
  37. } {1 {can't read "a": no such variable}}
  38.  
  39. # Basic array operations.
  40.  
  41. catch {unset a}
  42. set a(xyz) 2
  43. set a(44) 3
  44. set {a(a long name)} test
  45. test set-2.1 {basic array operations} {
  46.     lsort [array names a]
  47. } {44 {a long name} xyz}
  48. test set-2.2 {basic array operations} {
  49.     set a(44)
  50. } 3
  51. test set-2.3 {basic array operations} {
  52.     set a(xyz)
  53. } 2
  54. test set-2.4 {basic array operations} {
  55.     set "a(a long name)"
  56. } test
  57. test set-2.5 {basic array operations} {
  58.     list [catch {set a(other)} msg] $msg
  59. } {1 {can't read "a(other)": no such element in array}}
  60. test set-2.6 {basic array operations} {
  61.     list [catch {set a} msg] $msg
  62. } {1 {can't read "a": no such variable}}
  63. test set-2.7 {basic array operations} {
  64.     format %s $a(44)
  65. } 3
  66. test set-2.8 {basic array operations} {
  67.     format %s $a(a long name)
  68. } test
  69. unset a(44)
  70. test set-2.9 {basic array operations} {
  71.     lsort [array names a]
  72. } {{a long name} xyz}
  73. test set-2.10 {basic array operations} {
  74.     catch {unset b}
  75.     list [catch {set b(123)} msg] $msg
  76. } {1 {can't read "b(123)": no such variable}}
  77. test set-2.11 {basic array operations} {
  78.     catch {unset b}
  79.     set b 44
  80.     list [catch {set b(123)} msg] $msg
  81. } {1 {can't read "b(123)": variable isn't array}}
  82. test set-2.12 {basic array operations} {
  83.     list [catch {set a} msg] $msg
  84. } {1 {can't read "a": no such variable}}
  85. test set-2.13 {basic array operations} {
  86.     list [catch {set a 14} msg] $msg
  87. } {1 {can't set "a": variable is array}}
  88. unset a
  89. test set-2.14 {basic array operations} {
  90.     list [catch {set a(xyz)} msg] $msg
  91. } {1 {can't read "a(xyz)": no such variable}}
  92.  
  93. # Test the set commands, and exercise the corner cases of the code
  94. # that parses array references into two parts.
  95.  
  96. test set-3.1 {set command} {
  97.     list [catch {set} msg] $msg
  98. } {1 {wrong # args: should be "set varName ?newValue?"}}
  99. test set-3.2 {set command} {
  100.     list [catch {set x y z} msg] $msg
  101. } {1 {wrong # args: should be "set varName ?newValue?"}}
  102. test set-3.3 {set command} {
  103.     catch {unset a}
  104.     list [catch {set a} msg] $msg
  105. } {1 {can't read "a": no such variable}}
  106. test set-3.4 {set command} {
  107.     catch {unset a}
  108.     set a(14) 83
  109.     list [catch {set a 22} msg] $msg
  110. } {1 {can't set "a": variable is array}}
  111.  
  112. # Test the corner-cases of parsing array names, using set and unset.
  113.  
  114. test set-4.1 {parsing array names} {
  115.     catch {unset a}
  116.     set a(()) 44
  117.     list [catch {array names a} msg] $msg
  118. } {0 ()}
  119. test set-4.2 {parsing array names} {
  120.     catch {unset a a(abcd}
  121.     set a(abcd 33
  122.     info exists a(abcd
  123. } 1
  124. test set-4.3 {parsing array names} {
  125.     catch {unset a a(abcd}
  126.     set a(abcd 33
  127.     list [catch {array names a} msg] $msg
  128. } {0 {}}
  129. test set-4.4 {parsing array names} {
  130.     catch {unset a abcd)}
  131.     set abcd) 33
  132.     info exists abcd)
  133. } 1
  134. test set-4.5 {parsing array names} {
  135.     set a(bcd yyy
  136.     catch {unset a}
  137.     list [catch {set a(bcd} msg] $msg
  138. } {0 yyy}
  139. test set-4.6 {parsing array names} {
  140.     catch {unset a}
  141.     set a 44
  142.     list [catch {set a(bcd test} msg] $msg
  143. } {0 test}
  144.  
  145. # Errors in reading variables
  146.  
  147. test set-5.1 {errors in reading variables} {
  148.     catch {unset a}
  149.     list [catch {set a} msg] $msg
  150. } {1 {can't read "a": no such variable}}
  151. test set-5.2 {errors in reading variables} {
  152.     catch {unset a}
  153.     set a 44
  154.     list [catch {set a(18)} msg] $msg
  155. } {1 {can't read "a(18)": variable isn't array}}
  156. test set-5.3 {errors in reading variables} {
  157.     catch {unset a}
  158.     set a(6) 44
  159.     list [catch {set a(18)} msg] $msg
  160. } {1 {can't read "a(18)": no such element in array}}
  161. test set-5.4 {errors in reading variables} {
  162.     catch {unset a}
  163.     set a(6) 44
  164.     list [catch {set a} msg] $msg
  165. } {1 {can't read "a": no such variable}}
  166.  
  167. # Errors and other special cases in writing variables
  168.  
  169. test set-6.1 {creating array during write} {
  170.     catch {unset a}
  171.     trace var a rwu ignore
  172.     list [catch {set a(14) 186} msg] $msg [array names a]
  173. } {0 186 14}
  174. test set-6.2 {errors in writing variables} {
  175.     catch {unset a}
  176.     set a xxx
  177.     list [catch {set a(14) 186} msg] $msg
  178. } {1 {can't set "a(14)": variable isn't array}}
  179. test set-6.3 {errors in writing variables} {
  180.     catch {unset a}
  181.     set a(100) yyy
  182.     list [catch {set a 2} msg] $msg
  183. } {1 {can't set "a": variable is array}}
  184. test set-6.4 {expanding variable size} {
  185.     catch {unset a}
  186.     list [set a short] [set a "longer name"] [set a "even longer name"] \
  187.         [set a "a much much truly longer name"]
  188. } {short {longer name} {even longer name} {a much much truly longer name}}
  189.  
  190. # Unset command, Tcl_UnsetVar procedures
  191.  
  192. test set-7.1 {unset command} {
  193.     catch {unset a}; catch {unset b}; catch {unset c}; catch {unset d}
  194.     set a 44
  195.     set b 55
  196.     set c 66
  197.     set d 77
  198.     unset a b c
  199.     list [catch {set a(0) 0}] [catch {set b(0) 0}] [catch {set c(0) 0}] \
  200.         [catch {set d(0) 0}]
  201. } {0 0 0 1}
  202. test set-7.2 {unset command} {
  203.     list [catch {unset} msg] $msg
  204. } {1 {wrong # args: should be "unset varName ?varName ...?"}}
  205. test set-7.3 {unset command} {
  206.     catch {unset a}
  207.     list [catch {unset a} msg] $msg
  208. } {1 {can't unset "a": no such variable}}
  209. test set-7.4 {unset command} {
  210.     catch {unset a}
  211.     set a 44
  212.     list [catch {unset a(14)} msg] $msg
  213. } {1 {can't unset "a(14)": variable isn't array}}
  214. test set-7.5 {unset command} {
  215.     catch {unset a}
  216.     set a(0) xx
  217.     list [catch {unset a(14)} msg] $msg
  218. } {1 {can't unset "a(14)": no such element in array}}
  219. test set-7.6 {unset command} {
  220.     catch {unset a}; catch {unset b}; catch {unset c}
  221.     set a foo
  222.     set c gorp
  223.     list [catch {unset a a a(14)} msg] $msg [info exists c]
  224. } {1 {can't unset "a": no such variable} 1}
  225. test set-7.7 {unsetting globals from within procedures} {
  226.     set y 0
  227.     proc p1 {} {
  228.     global y
  229.     set z [p2]
  230.     return [list $z [catch {set y} msg] $msg]
  231.     }
  232.     proc p2 {} {global y; unset y; list [catch {set y} msg] $msg}
  233.     p1
  234. } {{1 {can't read "y": no such variable}} 1 {can't read "y": no such variable}}
  235. test set-7.8 {unsetting globals from within procedures} {
  236.     set y 0
  237.     proc p1 {} {
  238.     global y
  239.     p2
  240.     return [list [catch {set y 44} msg] $msg]
  241.     }
  242.     proc p2 {} {global y; unset y}
  243.     concat [p1] [list [catch {set y} msg] $msg]
  244. } {0 44 0 44}
  245. test set-7.9 {unsetting globals from within procedures} {
  246.     set y 0
  247.     proc p1 {} {
  248.     global y
  249.     unset y
  250.     return [list [catch {set y 55} msg] $msg]
  251.     }
  252.     concat [p1] [list [catch {set y} msg] $msg]
  253. } {0 55 0 55}
  254. test set-7.10 {unset command} {
  255.     catch {unset a}
  256.     set a(14) 22
  257.     unset a(14)
  258.     list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2
  259. } {1 {can't read "a(14)": no such element in array} 0 {}}
  260. test set-7.11 {unset command} {
  261.     catch {unset a}
  262.     set a(14) 22
  263.     unset a
  264.     list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2
  265. } {1 {can't read "a(14)": no such variable} 0 {}}
  266.  
  267. # Array command.
  268.  
  269. test set-8.1 {array command} {
  270.     list [catch {array} msg] $msg
  271. } {1 {wrong # args: should be "array option arrayName ?arg ...?"}}
  272. test set-8.2 {array command} {
  273.     list [catch {array a} msg] $msg
  274. } {1 {wrong # args: should be "array option arrayName ?arg ...?"}}
  275. test set-8.3 {array command} {
  276.     catch {unset a}
  277.     list [catch {array anymore a b} msg] $msg
  278. } {1 {"a" isn't an array}}
  279. test set-8.4 {array command} {
  280.     catch {unset a}
  281.     set a 44
  282.     list [catch {array anymore a b} msg] $msg
  283. } {1 {"a" isn't an array}}
  284. test set-8.5 {array command} {
  285.     proc foo {} {
  286.     set a 44
  287.     upvar 0 a x
  288.     list [catch {array anymore x b} msg] $msg
  289.     }
  290.     foo
  291. } {1 {"x" isn't an array}}
  292. test set-8.6 {array command} {
  293.     catch {unset a}
  294.     set a(22) 3
  295.     list [catch {array gorp a} msg] $msg
  296. } {1 {bad option "gorp": should be anymore, donesearch, exists, get, names, nextelement, set, size, or startsearch}}
  297. test set-8.7 {array command, anymore option} {
  298.     catch {unset a}
  299.     list [catch {array anymore a x} msg] $msg
  300. } {1 {"a" isn't an array}}
  301. test set-8.8 {array command, donesearch option} {
  302.     catch {unset a}
  303.     list [catch {array donesearch a x} msg] $msg
  304. } {1 {"a" isn't an array}}
  305. test set-8.9 {array command, exists option} {
  306.     list [catch {array exists a b} msg] $msg
  307. } {1 {wrong # args: should be "array exists arrayName"}}
  308. test set-8.10 {array command, exists option} {
  309.     catch {unset a}
  310.     array exists a
  311. } {0}
  312. test set-8.11 {array command, exists option} {
  313.     catch {unset a}
  314.     set a(0) 1
  315.     array exists a
  316. } {1}
  317. test set-8.12 {array command, get option} {
  318.     list [catch {array get a x} msg] $msg
  319. } {1 {wrong # args: should be "array get arrayName"}}
  320. test set-8.13 {array command, get option} {
  321.     catch {unset a}
  322.     array get a
  323. } {}
  324. test set-8.14 {array command, get option} {
  325.     catch {unset a}
  326.     set a(22) 3
  327.     set {a(long name)} {}
  328.     array get a
  329. } {22 3 {long name} {}}
  330. test set-8.15 {array command, get option (unset variable)} {
  331.     catch {unset a}
  332.     set a(x) 3
  333.     trace var a(y) w ignore
  334.     array get a
  335. } {x 3}
  336. test set-8.16 {array command, names option} {
  337.     catch {unset a}
  338.     set a(22) 3
  339.     list [catch {array names a 4 5} msg] $msg
  340. } {1 {wrong # args: should be "array names arrayName ?pattern?"}}
  341. test set-8.17 {array command, names option} {
  342.     catch {unset a}
  343.     array names a
  344. } {}
  345. test set-8.18 {array command, names option} {
  346.     catch {unset a}
  347.     set a(22) 3; set a(Textual_name) 44; set "a(name with spaces)" xxx
  348.     list [catch {lsort [array names a]} msg] $msg
  349. } {0 {22 Textual_name {name with spaces}}}
  350. test set-8.19 {array command, names option} {
  351.     catch {unset a}
  352.     set a(22) 3; set a(33) 44;
  353.     trace var a(xxx) w ignore
  354.     list [catch {lsort [array names a]} msg] $msg
  355. } {0 {22 33}}
  356. test set-8.20 {array command, names option} {
  357.     catch {unset a}
  358.     set a(22) 3; set a(33) 44;
  359.     trace var a(xxx) w ignore
  360.     set a(xxx) value
  361.     list [catch {lsort [array names a]} msg] $msg
  362. } {0 {22 33 xxx}}
  363. test set-8.21 {array command, names option} {
  364.     catch {unset a}
  365.     set a(axy) 3
  366.     set a(bxy) 44
  367.     set a(no) yes
  368.     set a(xxx) value
  369.     list [lsort [array names a *xy]] [lsort [array names a]]
  370. } {{axy bxy} {axy bxy no xxx}}
  371. test set-8.22 {array command, nextelement option} {
  372.     list [catch {array nextelement a} msg] $msg
  373. } {1 {wrong # args: should be "array nextelement arrayName searchId"}}
  374. test set-8.23 {array command, nextelement option} {
  375.     catch {unset a}
  376.     list [catch {array nextelement a b} msg] $msg
  377. } {1 {"a" isn't an array}}
  378. test set-8.24 {array command, set option} {
  379.     list [catch {array set a} msg] $msg
  380. } {1 {wrong # args: should be "array set arrayName list"}}
  381. test set-8.25 {array command, set option} {
  382.     list [catch {array set a 1 2} msg] $msg
  383. } {1 {wrong # args: should be "array set arrayName list"}}
  384. test set-8.26 {array command, set option} {
  385.     list [catch {array set a "a \{ c"} msg] $msg
  386. } {1 {unmatched open brace in list}}
  387. test set-8.27 {array command, set option} {
  388.     catch {unset a}
  389.     set a 44
  390.     list [catch {array set a {a b c d}} msg] $msg
  391. } {1 {can't set "a(a)": variable isn't array}}
  392. test set-8.28 {array command, set option} {
  393.     catch {unset a}
  394.     set a(xx) yy
  395.     array set a {b c d e}
  396.     array get a
  397. } {d e xx yy b c}
  398. test set-8.29 {array command, size option} {
  399.     list [catch {array size a 4} msg] $msg
  400. } {1 {wrong # args: should be "array size arrayName"}}
  401. test set-8.30 {array command, size option} {
  402.     catch {unset a}
  403.     array size a
  404. } {0}
  405. test set-8.31 {array command, size option} {
  406.     catch {unset a}
  407.     set a(22) 3; set a(Textual_name) 44; set "a(name with spaces)" xxx
  408.     list [catch {array size a} msg] $msg
  409. } {0 3}
  410. test set-8.32 {array command, size option} {
  411.     catch {unset a}
  412.     set a(22) 3; set a(xx) 44; set a(y) xxx
  413.     unset a(22) a(y) a(xx)
  414.     list [catch {array size a} msg] $msg
  415. } {0 0}
  416. test set-8.33 {array command, size option} {
  417.     catch {unset a}
  418.     set a(22) 3;
  419.     trace var a(33) rwu ignore
  420.     list [catch {array size a} msg] $msg
  421. } {0 1}
  422. test set-8.34 {array command, startsearch option} {
  423.     list [catch {array startsearch a b} msg] $msg
  424. } {1 {wrong # args: should be "array startsearch arrayName"}}
  425. test set-8.35 {array command, startsearch option} {
  426.     catch {unset a}
  427.     list [catch {array startsearch a} msg] $msg
  428. } {1 {"a" isn't an array}}
  429.  
  430. test set-9.1 {ids for array enumeration} {
  431.     catch {unset a}
  432.     set a(a) 1
  433.     list [array st a] [array st a] [array done a s-1-a; array st a] \
  434.         [array done a s-2-a; array d a s-3-a; array start a]
  435. } {s-1-a s-2-a s-3-a s-1-a}
  436. test set-9.2 {array enumeration} {
  437.     catch {unset a}
  438.     set a(a) 1
  439.     set a(b) 1
  440.     set a(c) 1
  441.     set x [array startsearch a]
  442.     list [array nextelement a $x] [array ne a $x] [array next a $x] \
  443.         [array next a $x] [array next a $x]
  444. } {a b c {} {}}
  445. test set-9.3 {array enumeration} {
  446.     catch {unset a}
  447.     set a(a) 1
  448.     set a(b) 1
  449.     set a(c) 1
  450.     set x [array startsearch a]
  451.     set y [array startsearch a]
  452.     set z [array startsearch a]
  453.     list [array nextelement a $x] [array ne a $x] \
  454.         [array next a $y] [array next a $z] [array next a $y] \
  455.         [array next a $z] [array next a $y] [array next a $z] \
  456.         [array next a $y] [array next a $z] [array next a $x] \
  457.         [array next a $x]
  458. } {a b a a b b c c {} {} c {}}
  459. test set-9.4 {array enumeration: stopping searches} {
  460.     catch {unset a}
  461.     set a(a) 1
  462.     set a(b) 1
  463.     set a(c) 1
  464.     set x [array startsearch a]
  465.     set y [array startsearch a]
  466.     set z [array startsearch a]
  467.     list [array next a $x] [array next a $x] [array next a $y] \
  468.         [array done a $z; array next a $x] \
  469.         [array done a $x; array next a $y] [array next a $y]
  470. } {a b a c b c}
  471. test set-9.5 {array enumeration: stopping searches} {
  472.     catch {unset a}
  473.     set a(a) 1
  474.     set x [array startsearch a]
  475.     array done a $x
  476.     list [catch {array next a $x} msg] $msg
  477. } {1 {couldn't find search "s-1-a"}}
  478. test set-9.6 {array enumeration: searches automatically stopped} {
  479.     catch {unset a}
  480.     set a(a) 1
  481.     set x [array startsearch a]
  482.     set y [array startsearch a]
  483.     set a(b) 1
  484.     list [catch {array next a $x} msg] $msg \
  485.         [catch {array next a $y} msg2] $msg2
  486. } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}}
  487. test set-9.7 {array enumeration: searches automatically stopped} {
  488.     catch {unset a}
  489.     set a(a) 1
  490.     set x [array startsearch a]
  491.     set y [array startsearch a]
  492.     set a(a) 2
  493.     list [catch {array next a $x} msg] $msg \
  494.         [catch {array next a $y} msg2] $msg2
  495. } {0 a 0 a}
  496. test set-9.8 {array enumeration: searches automatically stopped} {
  497.     catch {unset a}
  498.     set a(a) 1
  499.     set a(c) 2
  500.     set x [array startsearch a]
  501.     set y [array startsearch a]
  502.     catch {unset a(c)}
  503.     list [catch {array next a $x} msg] $msg \
  504.         [catch {array next a $y} msg2] $msg2
  505. } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}}
  506. test set-9.9 {array enumeration: searches automatically stopped} {
  507.     catch {unset a}
  508.     set a(a) 1
  509.     set x [array startsearch a]
  510.     set y [array startsearch a]
  511.     catch {unset a(c)}
  512.     list [catch {array next a $x} msg] $msg \
  513.         [catch {array next a $y} msg2] $msg2
  514. } {0 a 0 a}
  515. test set-9.10 {array enumeration: searches automatically stopped} {
  516.     catch {unset a}
  517.     set a(a) 1
  518.     set x [array startsearch a]
  519.     set y [array startsearch a]
  520.     trace var a(b) r {}
  521.     list [catch {array next a $x} msg] $msg \
  522.         [catch {array next a $y} msg2] $msg2
  523. } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}}
  524. test set-9.11 {array enumeration: searches automatically stopped} {
  525.     catch {unset a}
  526.     set a(a) 1
  527.     set x [array startsearch a]
  528.     set y [array startsearch a]
  529.     trace var a(a) r {}
  530.     list [catch {array next a $x} msg] $msg \
  531.         [catch {array next a $y} msg2] $msg2
  532. } {0 a 0 a}
  533. test set-9.12 {array enumeration with traced undefined elements} {
  534.     catch {unset a}
  535.     set a(a) 1
  536.     trace var a(b) r {}
  537.     set x [array startsearch a]
  538.     list [array next a $x] [array next a $x]
  539. } {a {}}
  540.  
  541. test set-10.1 {array enumeration errors} {
  542.     list [catch {array start} msg] $msg
  543. } {1 {wrong # args: should be "array option arrayName ?arg ...?"}}
  544. test set-10.2 {array enumeration errors} {
  545.     list [catch {array start a b} msg] $msg
  546. } {1 {wrong # args: should be "array startsearch arrayName"}}
  547. test set-10.3 {array enumeration errors} {
  548.     catch {unset a}
  549.     list [catch {array start a} msg] $msg
  550. } {1 {"a" isn't an array}}
  551. test set-10.4 {array enumeration errors} {
  552.     catch {unset a}
  553.     set a(a) 1
  554.     set x [array startsearch a]
  555.     list [catch {array next a} msg] $msg
  556. } {1 {wrong # args: should be "array nextelement arrayName searchId"}}
  557. test set-10.5 {array enumeration errors} {
  558.     catch {unset a}
  559.     set a(a) 1
  560.     set x [array startsearch a]
  561.     list [catch {array next a b c} msg] $msg
  562. } {1 {wrong # args: should be "array nextelement arrayName searchId"}}
  563. test set-10.6 {array enumeration errors} {
  564.     catch {unset a}
  565.     set a(a) 1
  566.     set x [array startsearch a]
  567.     list [catch {array next a a-1-a} msg] $msg
  568. } {1 {illegal search identifier "a-1-a"}}
  569. test set-10.7 {array enumeration errors} {
  570.     catch {unset a}
  571.     set a(a) 1
  572.     set x [array startsearch a]
  573.     list [catch {array next a sx1-a} msg] $msg
  574. } {1 {illegal search identifier "sx1-a"}}
  575. test set-10.8 {array enumeration errors} {
  576.     catch {unset a}
  577.     set a(a) 1
  578.     set x [array startsearch a]
  579.     list [catch {array next a s--a} msg] $msg
  580. } {1 {illegal search identifier "s--a"}}
  581. test set-10.9 {array enumeration errors} {
  582.     catch {unset a}
  583.     set a(a) 1
  584.     set x [array startsearch a]
  585.     list [catch {array next a s-1-b} msg] $msg
  586. } {1 {search identifier "s-1-b" isn't for variable "a"}}
  587. test set-10.10 {array enumeration errors} {
  588.     catch {unset a}
  589.     set a(a) 1
  590.     set x [array startsearch a]
  591.     list [catch {array next a s-1ba} msg] $msg
  592. } {1 {illegal search identifier "s-1ba"}}
  593. test set-10.11 {array enumeration errors} {
  594.     catch {unset a}
  595.     set a(a) 1
  596.     set x [array startsearch a]
  597.     list [catch {array next a s-2-a} msg] $msg
  598. } {1 {couldn't find search "s-2-a"}}
  599. test set-10.12 {array enumeration errors} {
  600.     list [catch {array done a} msg] $msg
  601. } {1 {wrong # args: should be "array donesearch arrayName searchId"}}
  602. test set-10.13 {array enumeration errors} {
  603.     list [catch {array done a b c} msg] $msg
  604. } {1 {wrong # args: should be "array donesearch arrayName searchId"}}
  605. test set-10.14 {array enumeration errors} {
  606.     list [catch {array done a b} msg] $msg
  607. } {1 {illegal search identifier "b"}}
  608. test set-10.15 {array enumeration errors} {
  609.     list [catch {array anymore a} msg] $msg
  610. } {1 {wrong # args: should be "array anymore arrayName searchId"}}
  611. test set-10.16 {array enumeration errors} {
  612.     list [catch {array any a b c} msg] $msg
  613. } {1 {wrong # args: should be "array anymore arrayName searchId"}}
  614. test set-10.17 {array enumeration errors} {
  615.     catch {unset a}
  616.     set a(0) 44
  617.     list [catch {array any a bogus} msg] $msg
  618. } {1 {illegal search identifier "bogus"}}
  619.  
  620. # Array enumeration with "anymore" option
  621.  
  622. test set-11.1 {array anymore option} {
  623.     catch {unset a}
  624.     set a(a) 1
  625.     set a(b) 2
  626.     set a(c) 3
  627.     array startsearch a
  628.     list [array anymore a s-1-a] [array next a s-1-a] \
  629.         [array anymore a s-1-a] [array next a s-1-a] \
  630.         [array anymore a s-1-a] [array next a s-1-a] \
  631.         [array anymore a s-1-a] [array next a s-1-a] 
  632. } {1 a 1 b 1 c 0 {}}
  633. test set-11.2 {array anymore option} {
  634.     catch {unset a}
  635.     set a(a) 1
  636.     set a(b) 2
  637.     set a(c) 3
  638.     array startsearch a
  639.     list [array next a s-1-a] [array next a s-1-a] \
  640.         [array anymore a s-1-a] [array next a s-1-a] \
  641.         [array next a s-1-a] [array anymore a s-1-a] 
  642. } {a b 1 c {} 0}
  643.  
  644. # Special check to see that the value of a variable is handled correctly
  645. # if it is returned as the result of a procedure (must not free the variable
  646. # string while deleting the call frame).  Errors will only be detected if
  647. # a memory consistency checker such as Purify is being used.
  648.  
  649. test set-12.1 {cleanup on procedure return} {
  650.     proc foo {} {
  651.     set x 12345
  652.     }
  653.     foo
  654. } 12345
  655. test set-12.2 {cleanup on procedure return} {
  656.     proc foo {} {
  657.     set x(1) 23456
  658.     }
  659.     foo
  660. } 23456
  661.  
  662. # Must delete variables when done, since these arrays get used as
  663. # scalars by other tests.
  664.  
  665. catch {unset a}
  666. catch {unset b}
  667. catch {unset c}
  668. return ""
  669.